package com.lohit.dbtest;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MenuActivity extends ListActivity {
	
	

	public static final String PREFS_NAME = "LoginCredentials";
	
	String[] list = { "Create Appointment", "View Appointments","Appointments For Existing Patients" };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_main);

 

		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, list));

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		
		super.onListItemClick(l, v, position, id);
		
		
		String dest = list[position];
		
		
		

		if (dest.equals("Create Appointment")) {
			
			
			Intent i = new Intent(MenuActivity.this,PatientDetailsActivity.class);
			startActivity(i);
			
			
		}
		if (dest.equals("View Appointments")) {
			
			
			Intent i = new Intent(MenuActivity.this,ScheduleAppActivity.class);
			startActivity(i);
			
			
		}
		if (dest.equals("Appointments For Existing Patients")) {
			
			
			Intent i = new Intent(MenuActivity.this,AutocompleteActivity.class);
			startActivity(i);
			
			
		}

		
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.logout) {
			SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
			
			SharedPreferences.Editor editor = settings.edit();
			editor.remove("id");
			editor.remove("username");
			editor.remove("logged");
			
			editor.commit();
			
			Log.d("sign out", "logged out");
			finish();
		}
		return super.onOptionsItemSelected(item);
	}
}
